package com.woniuxy.controller;

import com.woniuxy.entity.User;
import com.woniuxy.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: 马宇航
 * @Todo: TODO
 * @DateTime: 25/08/26/星期二 17:31
 * @Component: 成都蜗牛学苑
 **/
@RestController
@RequestMapping("/user")
@CrossOrigin
public class UserController {
    @Autowired
    UserService userService;
    @GetMapping("/")
    public ResponseEntity getUsers(){
        List<User> users = userService.findAll();
        return ResponseEntity.ok(users);
    }

    @GetMapping("/{username}")
    public ResponseEntity getUserByUsername(@PathVariable(value = "username") String username){
        User user = userService.findUserByUsername(username);
        return ResponseEntity.ok(user);
    }
    @PutMapping("/")
    public ResponseEntity updateUser(@RequestBody User user){
        int i = userService.updateOne(user);
        return ResponseEntity.ok(i);
    }
}
